package com.hjy.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hjy.common.domain.request.GoodsReq;
import com.hjy.common.domain.response.GoodsRes;
import com.hjy.common.result.Goods;
import com.hjy.common.result.Result;
import com.hjy.common.result.User;
import com.hjy.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class GoodsController {
    @Autowired
    private GoodsService goodsService;
    /**
     * 列表展示
     */
    @PostMapping("/goodsList")
    public Result<PageInfo<GoodsRes>> goodsList(@RequestBody GoodsReq req){
        PageHelper.startPage(req.getPageNum(), req.getPageSize());
        List<GoodsRes> list = goodsService.goodsList(req);
        PageInfo<GoodsRes> pageInfo = new PageInfo<>(list);


        return Result.success(pageInfo);
    }

    /**
     * 回显
     */
    @GetMapping("/byid/{id}")
    public Result<Goods> byId(@PathVariable Integer id){
        Goods byIe = goodsService.byId(id);
        return Result.success(byIe);
    }
    /**
     * 购买 商品
     */
    @PostMapping("/money")
    public Result money(@RequestBody Goods goods){
       return goodsService.money(goods);
    }
    /**
     * 抽奖
     */
    @GetMapping("/numGoods")
    public Result numGoods(){
        Result result = goodsService.numGoods();
        return result;
    }

    /**
     * 登录的回显
     */
    @GetMapping("/userById")
    public Result<User>  userById(){
        User user = goodsService.userById();
        return Result.success(user);
    }


}
